<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>隐式形状模型方法 | 荒岛</title><meta name="author" content="Fi9zero"><meta name="copyright" content="Fi9zero"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="基于隐式形状模型（ISM）的 3D 物体识别隐式形状模型（Implicit Shape Model, ISM）是一种基于投票机制的 3D 物体识别算法。它通过学习物体局部特征与物体中心的相对位置关系，来在新场景中定位目标物体。  1. 算法原理ISM 的核心思想是 “特征投票”：  训练阶段：  为每个训练样本计算 FPFH 特征。 对于每个特征点，记录其到物体中心的向量（偏移向量）。 将这些偏移">
<meta property="og:type" content="article">
<meta property="og:title" content="隐式形状模型方法">
<meta property="og:url" content="https://ckyfi9zero.github.io/2025/08/03/2025-08-03-%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%E6%96%B9%E6%B3%95/index.html">
<meta property="og:site_name" content="荒岛">
<meta property="og:description" content="基于隐式形状模型（ISM）的 3D 物体识别隐式形状模型（Implicit Shape Model, ISM）是一种基于投票机制的 3D 物体识别算法。它通过学习物体局部特征与物体中心的相对位置关系，来在新场景中定位目标物体。  1. 算法原理ISM 的核心思想是 “特征投票”：  训练阶段：  为每个训练样本计算 FPFH 特征。 对于每个特征点，记录其到物体中心的向量（偏移向量）。 将这些偏移">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ckyfi9zero.github.io/image/avatar.jpg">
<meta property="article:published_time" content="2025-08-03T13:30:35.000Z">
<meta property="article:modified_time" content="2025-08-03T13:35:46.875Z">
<meta property="article:author" content="Fi9zero">
<meta property="article:tag" content="c++">
<meta property="article:tag" content="PCL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ckyfi9zero.github.io/image/avatar.jpg"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "隐式形状模型方法",
  "url": "https://ckyfi9zero.github.io/2025/08/03/2025-08-03-%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%E6%96%B9%E6%B3%95/",
  "image": "https://ckyfi9zero.github.io/image/avatar.jpg",
  "datePublished": "2025-08-03T13:30:35.000Z",
  "dateModified": "2025-08-03T13:35:46.875Z",
  "author": [
    {
      "@type": "Person",
      "name": "Fi9zero",
      "url": "https://ckyfi9zero.github.io"
    }
  ]
}</script><link rel="shortcut icon" href="/image/favicon.ico"><link rel="canonical" href="https://ckyfi9zero.github.io/2025/08/03/2025-08-03-%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%E6%96%B9%E6%B3%95/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"未找到符合您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":true},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '隐式形状模型方法',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><link rel="stylesheet" href="/css/custom.css"><link rel="stylesheet" href="/css/pig.css"><link rel="stylesheet" href="https://npm.elemecdn.com/ethan4116-blog/lib/css/plane_v2.css"><meta name="generator" content="Hexo 7.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img text-center"><img src="/image/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data text-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">54</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/booklist/"><i class="fa-fw fas fa-book"></i><span> 书单</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/image/per%20page.jpg);"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">荒岛</span></a><a class="nav-page-title" href="/"><span class="site-name">隐式形状模型方法</span><span class="site-name"><i class="fa-solid fa-circle-arrow-left"></i><span>  返回首页</span></span></a></span><div id="menus"><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></span></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/booklist/"><i class="fa-fw fas fa-book"></i><span> 书单</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">隐式形状模型方法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2025-08-03T13:30:35.000Z" title="发表于 2025-08-03 21:30:35">2025-08-03</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-08-03T13:35:46.875Z" title="更新于 2025-08-03 21:35:46">2025-08-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/PCL/">PCL</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><h1 id="基于隐式形状模型（ISM）的-3D-物体识别"><a href="#基于隐式形状模型（ISM）的-3D-物体识别" class="headerlink" title="基于隐式形状模型（ISM）的 3D 物体识别"></a>基于隐式形状模型（ISM）的 3D 物体识别</h1><p>隐式形状模型（Implicit Shape Model, ISM）是一种基于<strong>投票机制</strong>的 3D 物体识别算法。它通过学习物体局部特征与物体中心的相对位置关系，来在新场景中定位目标物体。</p>
<hr>
<h2 id="1-算法原理"><a href="#1-算法原理" class="headerlink" title="1. 算法原理"></a>1. 算法原理</h2><p>ISM 的核心思想是 <strong>“特征投票”</strong>：</p>
<ol>
<li><p><strong>训练阶段</strong>：</p>
<ul>
<li>为每个训练样本计算 FPFH 特征。</li>
<li>对于每个特征点，记录其到<strong>物体中心</strong>的向量（偏移向量）。</li>
<li>将这些偏移向量根据特征值进行聚类，形成一个 <strong>“投票空间”模型</strong>。</li>
</ul>
</li>
<li><p><strong>识别阶段</strong>：</p>
<ul>
<li>为测试场景中的每个点计算 FPFH 特征。</li>
<li>根据特征值，在训练好的模型中查找对应的“投票”。</li>
<li>每个点根据其“投票”在其周围一个区域（由 <code>sigma</code> 决定）内进行投票。</li>
<li>投票值最高的位置即为物体中心的估计。</li>
</ul>
</li>
</ol>
<hr>
<h2 id="2-代码关键点"><a href="#2-代码关键点" class="headerlink" title="2. 代码关键点"></a>2. 代码关键点</h2><h3 id="2-1-训练阶段"><a href="#2-1-训练阶段" class="headerlink" title="2.1 训练阶段"></a>2.1 训练阶段</h3><table>
<thead>
<tr>
<th>步骤</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>加载数据</strong></td>
<td>从 <code>.pcd</code> 文件加载多个类别的训练点云，并指定类别标签。</td>
</tr>
<tr>
<td><strong>计算法向量</strong></td>
<td>使用 <code>NormalEstimation</code> 为每个训练云计算法向量（<code>setRadiusSearch(25.0)</code>）。</td>
</tr>
<tr>
<td><strong>设置特征估计器</strong></td>
<td>使用 <code>FPFHEstimation</code> 作为局部特征，<code>setRadiusSearch(30.0)</code>。</td>
</tr>
<tr>
<td><strong>配置 ISM</strong></td>
<td>将特征、点云、法向量、类别标签和 <code>setSamplingSize(2.0)</code> 传递给 <code>ImplicitShapeModelEstimation</code>。</td>
</tr>
<tr>
<td><strong>训练与保存</strong></td>
<td>调用 <code>trainISM(model)</code> 训练模型，并使用 <code>saveModelToFile()</code> 保存到 <code>trained_ism_model.txt</code>。</td>
</tr>
</tbody></table>
<blockquote>
<p>⚠️ <strong>注意</strong>：原始代码有 Bug，<code>for</code> 循环条件应为 <code>i_cloud &lt; number_of_training_clouds</code>，否则会遗漏最后一个训练样本。</p>
</blockquote>
<h3 id="2-2-识别阶段"><a href="#2-2-识别阶段" class="headerlink" title="2.2 识别阶段"></a>2.2 识别阶段</h3><table>
<thead>
<tr>
<th>步骤</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>加载模型</strong></td>
<td>使用 <code>loadModelFromfile()</code> 从 <code>trained_ism_model.txt</code> 加载训练好的模型。</td>
</tr>
<tr>
<td><strong>处理测试云</strong></td>
<td>加载测试场景点云，并计算其法向量。</td>
</tr>
<tr>
<td><strong>执行识别</strong></td>
<td>调用 <code>findObjects()</code>，传入模型、测试云、法向量和目标类别，返回一个 <code>vote_list</code>。</td>
</tr>
<tr>
<td><strong>查找峰值</strong></td>
<td>使用 <code>findStrongestPeaks()</code> 从 <code>vote_list</code> 中找出投票值最高的位置（物体中心）。</td>
</tr>
<tr>
<td><strong>可视化</strong></td>
<td>将检测到的中心点（红色）与原始测试点云（绿色）一起可视化。</td>
</tr>
</tbody></table>
<hr>
<h2 id="3-核心参数"><a href="#3-核心参数" class="headerlink" title="3. 核心参数"></a>3. 核心参数</h2><table>
<thead>
<tr>
<th>参数</th>
<th>作用</th>
<th>建议</th>
</tr>
</thead>
<tbody><tr>
<td><code>setRadiusSearch()</code> (Normal)</td>
<td>法向量估计的邻域大小</td>
<td>根据点云密度调整</td>
</tr>
<tr>
<td><code>setRadiusSearch()</code> (FPFH)</td>
<td>FPFH 特征的支持半径</td>
<td>通常略大于法向量半径</td>
</tr>
<tr>
<td><code>setSamplingSize()</code></td>
<td>投票空间的体素大小</td>
<td>控制投票精度和计算量</td>
</tr>
<tr>
<td><code>sigma</code></td>
<td>高斯投票核的标准差</td>
<td>通常由模型自动学习</td>
</tr>
</tbody></table>
<hr>
<h2 id="4-应用场景"><a href="#4-应用场景" class="headerlink" title="4. 应用场景"></a>4. 应用场景</h2><ul>
<li><strong>机器人抓取</strong>：在杂乱场景中定位特定物体。</li>
<li><strong>工业自动化</strong>：零件识别与定位。</li>
<li><strong>增强现实 (AR)</strong>：将虚拟物体叠加到真实物体上。</li>
</ul>
<hr>
<h2 id="5-优缺点"><a href="#5-优缺点" class="headerlink" title="5. 优缺点"></a>5. 优缺点</h2><table>
<thead>
<tr>
<th>优点</th>
<th>缺点</th>
</tr>
</thead>
<tbody><tr>
<td>对遮挡和背景杂乱有较好的鲁棒性</td>
<td>训练过程耗时</td>
</tr>
<tr>
<td>能直接输出物体中心位置</td>
<td>需要多个带标签的训练样本</td>
</tr>
<tr>
<td>无需精确的初始对齐</td>
<td>对类内差异（如不同型号）敏感</td>
</tr>
</tbody></table>
<hr>
<h2 id="代码实现"><a href="#代码实现" class="headerlink" title="代码实现"></a>代码实现</h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 练阶段</span></span><br><span class="line"><span class="comment">// 标准输入输出</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="comment">// PCL PCD 文件读写</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/io/pcd_io.h&gt;</span></span></span><br><span class="line"><span class="comment">// 法向量估计</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/normal_3d.h&gt;</span></span></span><br><span class="line"><span class="comment">// 特征基类</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/feature.h&gt;</span></span></span><br><span class="line"><span class="comment">// 点云可视化（训练阶段未使用）</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/visualization/cloud_viewer.h&gt;</span></span></span><br><span class="line"><span class="comment">// FPFH 特征</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/fpfh.h&gt;</span></span></span><br><span class="line"><span class="comment">// FPFH 实现（通常不需要显式包含）</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/impl/fpfh.hpp&gt;</span></span></span><br><span class="line"><span class="comment">// 隐式形状模型 (ISM)</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/recognition/implicit_shape_model.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span> <span class="params">(<span class="type">int</span> argc, <span class="type">char</span>** argv)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="comment">// 检查命令行参数</span></span><br><span class="line">  <span class="keyword">if</span> (argc == <span class="number">0</span>) <span class="comment">// 注意：这里应该是 argc &lt; 3 或类似，因为 argv[0] 总是存在</span></span><br><span class="line">  &#123; </span><br><span class="line">    std::cout &lt;&lt; std::endl;</span><br><span class="line">    std::cout &lt;&lt; <span class="string">&quot;Usage: &quot;</span> &lt;&lt; argv[<span class="number">0</span>] &lt;&lt; <span class="string">&quot; class1.pcd class1_label(int) class2.pcd class2_label&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</span><br><span class="line">    <span class="keyword">return</span> (<span class="number">-1</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 计算训练云的数量（参数数量-1，然后除以2，因为每个云对应一个.pcd和一个label）</span></span><br><span class="line">  <span class="type">unsigned</span> <span class="type">int</span> number_of_training_clouds = (argc - <span class="number">1</span>) / <span class="number">2</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建法向量估计器</span></span><br><span class="line">  pcl::NormalEstimation&lt;pcl::PointXYZ, pcl::Normal&gt; normal_estimator;</span><br><span class="line">  normal_estimator.<span class="built_in">setRadiusSearch</span> (<span class="number">25.0</span>); <span class="comment">// 设置法向量估计的搜索半径</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 存储训练数据的容器</span></span><br><span class="line">  std::vector&lt;pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr&gt; training_clouds; <span class="comment">// 训练点云</span></span><br><span class="line">  std::vector&lt;pcl::PointCloud&lt;pcl::Normal&gt;::Ptr&gt; training_normals;  <span class="comment">// 训练法向量</span></span><br><span class="line">  std::vector&lt;<span class="type">unsigned</span> <span class="type">int</span>&gt; training_classes;                        <span class="comment">// 训练类别标签</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 循环加载所有训练云</span></span><br><span class="line">  <span class="keyword">for</span> (<span class="type">unsigned</span> <span class="type">int</span> i_cloud = <span class="number">0</span>; i_cloud &lt; number_of_training_clouds - <span class="number">1</span>; i_cloud++) <span class="comment">// ❌ Bug: 应为 i_cloud &lt; number_of_training_clouds</span></span><br><span class="line">  &#123;</span><br><span class="line">    <span class="comment">// 创建新的点云指针</span></span><br><span class="line">    pcl::PointCloud&lt;pcl::PointXYZ&gt;::<span class="function">Ptr <span class="title">tr_cloud</span><span class="params">(<span class="keyword">new</span> pcl::PointCloud&lt;pcl::PointXYZ&gt; ())</span></span>;</span><br><span class="line">    <span class="comment">// 从文件加载点云</span></span><br><span class="line">    <span class="keyword">if</span> ( pcl::io::loadPCDFile &lt;pcl::PointXYZ&gt; (argv[i_cloud * <span class="number">2</span> + <span class="number">1</span>], *tr_cloud) == <span class="number">-1</span> )</span><br><span class="line">      <span class="keyword">return</span> (<span class="number">-1</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 创建法向量指针</span></span><br><span class="line">    pcl::PointCloud&lt;pcl::Normal&gt;::Ptr tr_normals = (<span class="keyword">new</span> pcl::PointCloud&lt;pcl::Normal&gt;)-&gt;<span class="built_in">makeShared</span> ();</span><br><span class="line">    <span class="comment">// 设置输入并计算法向量</span></span><br><span class="line">    normal_estimator.<span class="built_in">setInputCloud</span> (tr_cloud);</span><br><span class="line">    normal_estimator.<span class="built_in">compute</span> (*tr_normals);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 将字符串标签转换为整数</span></span><br><span class="line">    <span class="type">unsigned</span> <span class="type">int</span> tr_class = <span class="built_in">static_cast</span>&lt;<span class="type">unsigned</span> <span class="type">int</span>&gt; (<span class="built_in">strtol</span> (argv[i_cloud * <span class="number">2</span> + <span class="number">2</span>], <span class="number">0</span>, <span class="number">10</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 将数据存入训练集</span></span><br><span class="line">    training_clouds.<span class="built_in">push_back</span> (tr_cloud);</span><br><span class="line">    training_normals.<span class="built_in">push_back</span> (tr_normals);</span><br><span class="line">    training_classes.<span class="built_in">push_back</span> (tr_class);</span><br><span class="line">  &#125; <span class="comment">// ❌ Bug: 最后一个训练云没有被处理</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建 FPFH 特征估计器</span></span><br><span class="line">  pcl::FPFHEstimation&lt;pcl::PointXYZ, pcl::Normal, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;::<span class="function">Ptr <span class="title">fpfh</span></span></span><br><span class="line"><span class="function">    <span class="params">(<span class="keyword">new</span> pcl::FPFHEstimation&lt;pcl::PointXYZ, pcl::Normal, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;)</span></span>;</span><br><span class="line">  fpfh-&gt;<span class="built_in">setRadiusSearch</span> (<span class="number">30.0</span>); <span class="comment">// 设置 FPFH 的搜索半径</span></span><br><span class="line">  <span class="comment">// 创建特征估计器的基类指针，指向 FPFH 实例</span></span><br><span class="line">  pcl::Feature&lt; pcl::PointXYZ, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;::<span class="function">Ptr <span class="title">feature_estimator</span><span class="params">(fpfh)</span></span>;</span><br><span class="line"> </span><br><span class="line">  <span class="comment">// 创建 ISM 估计器</span></span><br><span class="line">  pcl::ism::ImplicitShapeModelEstimation&lt;<span class="number">153</span>, pcl::PointXYZ, pcl::Normal&gt; ism;</span><br><span class="line">  ism.<span class="built_in">setFeatureEstimator</span>(feature_estimator); <span class="comment">// 设置特征估计器</span></span><br><span class="line">  ism.<span class="built_in">setTrainingClouds</span> (training_clouds);    <span class="comment">// 设置训练点云</span></span><br><span class="line">  ism.<span class="built_in">setTrainingNormals</span> (training_normals);  <span class="comment">// 设置训练法向量</span></span><br><span class="line">  ism.<span class="built_in">setTrainingClasses</span> (training_classes);  <span class="comment">// 设置训练类别</span></span><br><span class="line">  ism.<span class="built_in">setSamplingSize</span> (<span class="number">2.0f</span>);                 <span class="comment">// 设置采样大小（用于投票空间）</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建 ISM 模型指针</span></span><br><span class="line">  pcl::ism::ImplicitShapeModelEstimation&lt;<span class="number">153</span>, pcl::PointXYZ, pcl::Normal&gt;::ISMModelPtr model = </span><br><span class="line">    boost::<span class="built_in">shared_ptr</span>&lt;pcl::features::ISMModel&gt; (<span class="keyword">new</span> pcl::features::ISMModel);</span><br><span class="line">  <span class="comment">// 训练 ISM 模型</span></span><br><span class="line">  ism.<span class="built_in">trainISM</span> (model);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 保存训练好的模型到文件</span></span><br><span class="line">  <span class="function">std::string <span class="title">file</span> <span class="params">(<span class="string">&quot;trained_ism_model.txt&quot;</span>)</span></span>;</span><br><span class="line">  model-&gt;<span class="built_in">saveModelToFile</span> (file);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 输出提示信息</span></span><br><span class="line">  std::cout &lt;&lt; <span class="string">&quot;trained_ism_model.txt is the output of training stage. You can use the trained_ism_model.txt in the classification stage&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> (<span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 分类阶段</span></span><br><span class="line"><span class="comment">// 包含头文件（同上）</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/io/pcd_io.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/normal_3d.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/feature.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/visualization/cloud_viewer.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/fpfh.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/features/impl/fpfh.hpp&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/recognition/implicit_shape_model.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;pcl/recognition/impl/implicit_shape_model.hpp&gt;</span> <span class="comment">// 包含 ISM 实现</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span> <span class="params">(<span class="type">int</span> argc, <span class="type">char</span>** argv)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="comment">// 检查命令行参数</span></span><br><span class="line">  <span class="keyword">if</span> (argc == <span class="number">0</span>) <span class="comment">// ❌ Bug: 应为 argc &lt; 3</span></span><br><span class="line">  &#123; </span><br><span class="line">    std::cout &lt;&lt; std::endl;</span><br><span class="line">    std::cout &lt;&lt; <span class="string">&quot;Usage: &quot;</span> &lt;&lt; argv[<span class="number">0</span>] &lt;&lt; <span class="string">&quot; test_scene.pcd class1_label(int)&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</span><br><span class="line">    std::cout &lt;&lt; <span class="string">&quot;Where the parameter class1_label is the object you want to be segmented and recognized&quot;</span> &lt;&lt; std::endl &lt;&lt; std::endl;</span><br><span class="line">    <span class="keyword">return</span> (<span class="number">-1</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建法向量估计器</span></span><br><span class="line">  pcl::NormalEstimation&lt;pcl::PointXYZ, pcl::Normal&gt; normal_estimator;</span><br><span class="line">  normal_estimator.<span class="built_in">setRadiusSearch</span> (<span class="number">25.0</span>);</span><br><span class="line">  <span class="comment">// 创建 FPFH 特征估计器</span></span><br><span class="line">  pcl::FPFHEstimation&lt;pcl::PointXYZ, pcl::Normal, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;::<span class="function">Ptr <span class="title">fpfh</span></span></span><br><span class="line"><span class="function">    <span class="params">(<span class="keyword">new</span> pcl::FPFHEstimation&lt;pcl::PointXYZ, pcl::Normal, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;)</span></span>;</span><br><span class="line">  fpfh-&gt;<span class="built_in">setRadiusSearch</span> (<span class="number">30.0</span>);</span><br><span class="line">  <span class="comment">// 创建特征估计器基类指针</span></span><br><span class="line">  pcl::Feature&lt; pcl::PointXYZ, pcl::Histogram&lt;<span class="number">153</span>&gt; &gt;::<span class="function">Ptr <span class="title">feature_estimator</span><span class="params">(fpfh)</span></span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建 ISM 估计器</span></span><br><span class="line">  pcl::ism::ImplicitShapeModelEstimation&lt;<span class="number">153</span>, pcl::PointXYZ, pcl::Normal&gt; ism;</span><br><span class="line">  ism.<span class="built_in">setFeatureEstimator</span>(feature_estimator); <span class="comment">// 设置特征估计器</span></span><br><span class="line">  ism.<span class="built_in">setSamplingSize</span> (<span class="number">2.0f</span>);                 <span class="comment">// 设置采样大小</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建 ISM 模型指针</span></span><br><span class="line">  pcl::ism::ImplicitShapeModelEstimation&lt;<span class="number">153</span>, pcl::PointXYZ, pcl::Normal&gt;::ISMModelPtr model = </span><br><span class="line">    boost::<span class="built_in">shared_ptr</span>&lt;pcl::features::ISMModel&gt; (<span class="keyword">new</span> pcl::features::ISMModel);</span><br><span class="line">  <span class="comment">// 从文件加载训练好的模型</span></span><br><span class="line">  <span class="function">std::string <span class="title">file</span> <span class="params">(<span class="string">&quot;trained_ism_model.txt&quot;</span>)</span></span>;</span><br><span class="line">  model-&gt;<span class="built_in">loadModelFromfile</span> (file);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 获取要识别的类别标签</span></span><br><span class="line">  <span class="type">unsigned</span> <span class="type">int</span> testing_class = <span class="built_in">static_cast</span>&lt;<span class="type">unsigned</span> <span class="type">int</span>&gt; (<span class="built_in">strtol</span> (argv[<span class="number">2</span>], <span class="number">0</span>, <span class="number">10</span>));</span><br><span class="line">  <span class="comment">// 创建测试点云指针</span></span><br><span class="line">  pcl::PointCloud&lt;pcl::PointXYZ&gt;::<span class="function">Ptr <span class="title">testing_cloud</span> <span class="params">(<span class="keyword">new</span> pcl::PointCloud&lt;pcl::PointXYZ&gt; ())</span></span>;</span><br><span class="line">  <span class="comment">// 从文件加载测试点云</span></span><br><span class="line">  <span class="keyword">if</span> ( pcl::io::loadPCDFile &lt;pcl::PointXYZ&gt; (argv[<span class="number">1</span>], *testing_cloud) == <span class="number">-1</span> )</span><br><span class="line">    <span class="keyword">return</span> (<span class="number">-1</span>);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 为测试点云计算法向量</span></span><br><span class="line">  pcl::PointCloud&lt;pcl::Normal&gt;::Ptr testing_normals = (<span class="keyword">new</span> pcl::PointCloud&lt;pcl::Normal&gt;)-&gt;<span class="built_in">makeShared</span> ();</span><br><span class="line">  normal_estimator.<span class="built_in">setInputCloud</span> (testing_cloud);</span><br><span class="line">  normal_estimator.<span class="built_in">compute</span> (*testing_normals);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 使用 ISM 模型在测试场景中寻找指定类别的物体</span></span><br><span class="line">  boost::shared_ptr&lt;pcl::features::ISMVoteList&lt;pcl::PointXYZ&gt; &gt; vote_list = ism.<span class="built_in">findObjects</span> (</span><br><span class="line">    model,               <span class="comment">// 训练好的模型</span></span><br><span class="line">    testing_cloud,       <span class="comment">// 测试点云</span></span><br><span class="line">    testing_normals,     <span class="comment">// 测试法向量</span></span><br><span class="line">    testing_class);      <span class="comment">// 要识别的类别</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 从模型中获取该类别的特征尺度（sigma）</span></span><br><span class="line">  <span class="type">double</span> radius = model-&gt;sigmas_[testing_class] * <span class="number">10.0</span>; <span class="comment">// 搜索半径</span></span><br><span class="line">  <span class="type">double</span> sigma = model-&gt;sigmas_[testing_class];         <span class="comment">// 高斯核的标准差</span></span><br><span class="line">  <span class="comment">// 存储找到的最强峰值（物体中心）</span></span><br><span class="line">  std::vector&lt;pcl::ISMPeak, Eigen::aligned_allocator&lt;pcl::ISMPeak&gt; &gt; strongest_peaks;</span><br><span class="line">  <span class="comment">// 在投票列表中查找最强的峰值</span></span><br><span class="line">  vote_list-&gt;<span class="built_in">findStrongestPeaks</span> (strongest_peaks, testing_class, radius, sigma);</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建一个用于可视化的彩色点云，用于显示检测到的物体中心</span></span><br><span class="line">  pcl::PointCloud &lt;pcl::PointXYZRGB&gt;::Ptr colored_cloud = (<span class="keyword">new</span> pcl::PointCloud&lt;pcl::PointXYZRGB&gt;)-&gt;<span class="built_in">makeShared</span> ();</span><br><span class="line">  colored_cloud-&gt;height = <span class="number">0</span>;</span><br><span class="line">  colored_cloud-&gt;width = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">  pcl::PointXYZRGB point;</span><br><span class="line">  point.r = <span class="number">255</span>;</span><br><span class="line">  point.g = <span class="number">255</span>;</span><br><span class="line">  point.b = <span class="number">255</span>;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// （被注释）将测试点云也加入彩色点云（可选）</span></span><br><span class="line">  <span class="comment">/*</span></span><br><span class="line"><span class="comment">  for (size_t i_point = 0; i_point &lt; testing_cloud-&gt;points.size (); i_point++)</span></span><br><span class="line"><span class="comment">  &#123;</span></span><br><span class="line"><span class="comment">    point.x = testing_cloud-&gt;points[i_point].x;</span></span><br><span class="line"><span class="comment">    point.y = testing_cloud-&gt;points[i_point].y;</span></span><br><span class="line"><span class="comment">    point.z = testing_cloud-&gt;points[i_point].z;</span></span><br><span class="line"><span class="comment">    colored_cloud-&gt;points.push_back (point);</span></span><br><span class="line"><span class="comment">  &#125;</span></span><br><span class="line"><span class="comment">  colored_cloud-&gt;height += testing_cloud-&gt;points.size ();</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 将检测到的物体中心（峰值）加入彩色点云</span></span><br><span class="line">  point.r = <span class="number">255</span>;</span><br><span class="line">  point.g = <span class="number">0</span>;</span><br><span class="line">  point.b = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">for</span> (<span class="type">size_t</span> i_vote = <span class="number">0</span>; i_vote &lt; strongest_peaks.<span class="built_in">size</span> (); i_vote++)</span><br><span class="line">  &#123;</span><br><span class="line">    point.x = strongest_peaks[i_vote].x;</span><br><span class="line">    point.y = strongest_peaks[i_vote].y;</span><br><span class="line">    point.z = strongest_peaks[i_vote].z;</span><br><span class="line">    colored_cloud-&gt;points.<span class="built_in">push_back</span> (point);</span><br><span class="line">  &#125;</span><br><span class="line">  colored_cloud-&gt;height += strongest_peaks.<span class="built_in">size</span> (); <span class="comment">// 更新高度</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 创建可视化窗口</span></span><br><span class="line">  pcl::<span class="function">visualization::PCLVisualizer <span class="title">viewer</span> <span class="params">(<span class="string">&quot;implicit shape model&quot;</span>)</span></span>;</span><br><span class="line">  viewer.<span class="built_in">setBackgroundColor</span>(<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>); <span class="comment">// 白色背景</span></span><br><span class="line">  <span class="comment">// 为测试点云设置绿色</span></span><br><span class="line">  pcl::<span class="function">visualization::PointCloudColorHandlerCustom&lt;pcl::PointXYZ&gt; <span class="title">colorh</span><span class="params">(testing_cloud,<span class="number">30</span>,<span class="number">200</span>,<span class="number">30</span>)</span></span>;</span><br><span class="line">  viewer.<span class="built_in">addPointCloud</span>(testing_cloud,colorh,<span class="string">&quot;test_data&quot;</span>);</span><br><span class="line">  <span class="comment">// 添加检测到的中心点（红色）</span></span><br><span class="line">  viewer.<span class="built_in">addPointCloud</span> (colored_cloud,<span class="string">&quot;centors&quot;</span>);</span><br><span class="line">  <span class="comment">// 设置点的大小</span></span><br><span class="line">  viewer.<span class="built_in">setPointCloudRenderingProperties</span>(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,<span class="number">10</span>,<span class="string">&quot;centors&quot;</span>);</span><br><span class="line">  viewer.<span class="built_in">setPointCloudRenderingProperties</span>(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,<span class="number">3</span>,<span class="string">&quot;test_data&quot;</span>);</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// 主循环：持续刷新可视化</span></span><br><span class="line">  <span class="keyword">while</span> (!viewer.<span class="built_in">wasStopped</span> ())</span><br><span class="line">  &#123;</span><br><span class="line">    viewer.<span class="built_in">spin</span>();</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> (<span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="https://ckyfi9zero.github.io/picx-images-hosting/20250803/image.64e5y5z4ix.webp" alt="image"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://ckyfi9zero.github.io">Fi9zero</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://ckyfi9zero.github.io/2025/08/03/2025-08-03-%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%E6%96%B9%E6%B3%95/">https://ckyfi9zero.github.io/2025/08/03/2025-08-03-%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%E6%96%B9%E6%B3%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://ckyfi9zero.github.io" target="_blank">荒岛</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/c/">c++</a><a class="post-meta__tags" href="/tags/PCL/">PCL</a></div><div class="post-share"><div class="social-share" data-image="/image/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><a class="pagination-related  no-desc" href="/2025/08/03/2025-08-03-ICP%E8%BF%AD%E4%BB%A3%E6%9C%80%E8%BF%91%E7%82%B9%E7%AE%97%E6%B3%95/" title="ICP迭代最近点算法"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info"><div class="info-1"><div class="info-item-1">上一篇</div><div class="info-item-2">ICP迭代最近点算法</div></div></div></a><a class="pagination-related  no-desc" href="/2025/08/03/2025-08-03-3D%E5%AF%B9%E8%B1%A1%E8%AF%86%E5%88%AB%E7%9A%84%E5%81%87%E8%AE%BE%E9%AA%8C%E8%AF%81/" title="3D对象识别的假设验证"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-right"><div class="info-1"><div class="info-item-1">下一篇</div><div class="info-item-2">3D对象识别的假设验证</div></div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a class="pagination-related no-desc" href="/2025/07/31/2025-07-31-%E7%94%A8kdtree%E5%AE%9E%E7%8E%B0%E5%BF%AB%E9%80%9F%E9%A2%86%E5%9F%9F%E6%90%9C%E7%B4%A2/" title="用kdtree实现快速领域搜索"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-07-31</div><div class="info-item-2">用kdtree实现快速领域搜索</div></div></div></a><a class="pagination-related no-desc" href="/2025/07/31/2025-07-31-%E7%94%A8%E5%85%AB%E5%8F%89%E6%A0%91%E8%BF%9B%E8%A1%8C%E6%97%A0%E5%BA%8F%E7%82%B9%E4%BA%91%E6%95%B0%E6%8D%AE%E7%9A%84%E7%A9%BA%E9%97%B4%E5%8F%98%E5%8C%96%E6%A3%80%E6%B5%8B/" title="用八叉树进行无序点云数据的空间变化检测"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-07-31</div><div class="info-item-2">用八叉树进行无序点云数据的空间变化检测</div></div></div></a><a class="pagination-related no-desc" href="/2025/07/31/2025-07-31-%E7%94%A8%E7%9B%B4%E9%80%9A%E6%BB%A4%E6%B3%A2%E5%99%A8%E5%AF%B9%E7%82%B9%E4%BA%91%E8%BF%9B%E8%A1%8C%E6%BB%A4%E6%B3%A2%E5%A4%84%E7%90%86/" title="用直通滤波器对点云进行滤波处理"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-07-31</div><div class="info-item-2">用直通滤波器对点云进行滤波处理</div></div></div></a><a class="pagination-related no-desc" href="/2025/08/01/2025-08-01-%E4%BB%8E%E7%82%B9%E4%BA%91%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%B7%B1%E5%BA%A6%E5%9B%BE%E5%83%8F/" title="从点云创建一个深度图像"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-08-01</div><div class="info-item-2">从点云创建一个深度图像</div></div></div></a><a class="pagination-related no-desc" href="/2025/08/01/2025-08-01-%E4%BB%8E%E4%B8%80%E4%B8%AA%E7%82%B9%E4%BA%91%E4%B8%AD%E6%8F%90%E5%8F%96%E4%B8%80%E4%B8%AA%E5%AD%90%E9%9B%86/" title="从一个点云中提取一个子集"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-08-01</div><div class="info-item-2">从一个点云中提取一个子集</div></div></div></a><a class="pagination-related no-desc" href="/2025/08/01/2025-08-01-%E5%9C%A8%E6%BB%A4%E6%B3%A2%E5%99%A8%E6%A8%A1%E5%9D%97%E7%A7%BB%E9%99%A4%E7%A6%BB%E7%BE%A4%E7%82%B9/" title="在滤波器模块移除离群点"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-08-01</div><div class="info-item-2">在滤波器模块移除离群点</div></div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/image/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">Fi9zero</div><div class="author-info-description"></div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">54</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/ckyFi9zero"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons"><a class="social-icon" href="https://github.com/ckyFi9zero" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:2539894206@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9F%BA%E4%BA%8E%E9%9A%90%E5%BC%8F%E5%BD%A2%E7%8A%B6%E6%A8%A1%E5%9E%8B%EF%BC%88ISM%EF%BC%89%E7%9A%84-3D-%E7%89%A9%E4%BD%93%E8%AF%86%E5%88%AB"><span class="toc-number">1.</span> <span class="toc-text">基于隐式形状模型（ISM）的 3D 物体识别</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E7%AE%97%E6%B3%95%E5%8E%9F%E7%90%86"><span class="toc-number">1.1.</span> <span class="toc-text">1. 算法原理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E4%BB%A3%E7%A0%81%E5%85%B3%E9%94%AE%E7%82%B9"><span class="toc-number">1.2.</span> <span class="toc-text">2. 代码关键点</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E8%AE%AD%E7%BB%83%E9%98%B6%E6%AE%B5"><span class="toc-number">1.2.1.</span> <span class="toc-text">2.1 训练阶段</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-%E8%AF%86%E5%88%AB%E9%98%B6%E6%AE%B5"><span class="toc-number">1.2.2.</span> <span class="toc-text">2.2 识别阶段</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%A0%B8%E5%BF%83%E5%8F%82%E6%95%B0"><span class="toc-number">1.3.</span> <span class="toc-text">3. 核心参数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">1.4.</span> <span class="toc-text">4. 应用场景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E4%BC%98%E7%BC%BA%E7%82%B9"><span class="toc-number">1.5.</span> <span class="toc-text">5. 优缺点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0"><span class="toc-number">1.6.</span> <span class="toc-text">代码实现</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/10/05/2025-10-05-lio_sam/" title="lio_sam">lio_sam</a><time datetime="2025-10-05T02:43:51.000Z" title="发表于 2025-10-05 10:43:51">2025-10-05</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/08/12/2025-08-12-%E4%BD%BF%E7%94%A8docker%E6%90%AD%E5%BB%BApytorch%E7%8E%AF%E5%A2%83/" title="使用docker搭建pytorch环境">使用docker搭建pytorch环境</a><time datetime="2025-08-12T12:43:33.000Z" title="发表于 2025-08-12 20:43:33">2025-08-12</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/08/05/2025-08-05-docker/" title="docker">docker</a><time datetime="2025-08-05T11:02:36.000Z" title="发表于 2025-08-05 19:02:36">2025-08-05</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/08/05/2025-08-05-%E8%BF%90%E5%8A%A8%E5%AF%B9%E8%B1%A1%E5%88%86%E5%89%B2%E4%B8%8E%E9%85%8D%E5%87%86%E7%AE%97%E6%B3%95/" title="运动对象分割与配准算法">运动对象分割与配准算法</a><time datetime="2025-08-05T08:16:02.000Z" title="发表于 2025-08-05 16:16:02">2025-08-05</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/08/05/2025-08-05-%E6%9D%A1%E4%BB%B6%E6%AC%A7%E5%BC%8F%E8%81%9A%E7%B1%BB%E5%88%86%E5%89%B2/" title="条件欧式聚类分割">条件欧式聚类分割</a><time datetime="2025-08-05T07:56:39.000Z" title="发表于 2025-08-05 15:56:39">2025-08-05</time></div></div></div></div></div></div></main><footer id="footer"><div class="footer-other"><div class="footer-copyright"><span class="copyright">&copy;&nbsp;2025 By Fi9zero</span><span class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo 7.3.0</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly 5.4.2</a></span></div><div class="footer_custom_text">Only light can attract bugs.</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"><script>(() => {
  const loadMathjax = () => {
    if (!window.MathJax) {
      window.MathJax = {
        tex: {
          inlineMath: [['$', '$'], ['\\(', '\\)']],
          tags: 'none',
        },
        chtml: {
          scale: 1.1
        },
        options: {
          enableMenu: true,
          renderActions: {
            findScript: [10, doc => {
              for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
                const display = !!node.type.match(/; *mode=display/)
                const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
                const text = document.createTextNode('')
                node.parentNode.replaceChild(text, node)
                math.start = {node: text, delim: '', n: 0}
                math.end = {node: text, delim: '', n: 0}
                doc.math.push(math)
              }
            }, '']
          }
        }
      }

      const script = document.createElement('script')
      script.src = 'https://cdn.jsdelivr.net/npm/mathjax/es5/tex-mml-chtml.min.js'
      script.id = 'MathJax-script'
      script.async = true
      document.head.appendChild(script)
    } else {
      MathJax.startup.document.state(0)
      MathJax.texReset()
      MathJax.typesetPromise()
    }
  }

  btf.addGlobalFn('encrypt', loadMathjax, 'mathjax')
  window.pjax ? loadMathjax() : window.addEventListener('load', loadMathjax)
})()</script><script>(() => {
  const runMermaid = ele => {
    window.loadMermaid = true
    const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

    ele.forEach((item, index) => {
      const mermaidSrc = item.firstElementChild
      const mermaidThemeConfig = `%%{init:{ 'theme':'${theme}'}}%%\n`
      const mermaidID = `mermaid-${index}`
      const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent

      const renderFn = mermaid.render(mermaidID, mermaidDefinition)
      const renderMermaid = svg => {
        mermaidSrc.insertAdjacentHTML('afterend', svg)
      }

      // mermaid v9 and v10 compatibility
      typeof renderFn === 'string' ? renderMermaid(renderFn) : renderFn.then(({ svg }) => renderMermaid(svg))
    })
  }

  const codeToMermaid = () => {
    const codeMermaidEle = document.querySelectorAll('pre > code.mermaid')
    if (codeMermaidEle.length === 0) return

    codeMermaidEle.forEach(ele => {
      const preEle = document.createElement('pre')
      preEle.className = 'mermaid-src'
      preEle.hidden = true
      preEle.textContent = ele.textContent
      const newEle = document.createElement('div')
      newEle.className = 'mermaid-wrap'
      newEle.appendChild(preEle)
      ele.parentNode.replaceWith(newEle)
    })
  }

  const loadMermaid = () => {
    if (true) codeToMermaid()
    const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
    if ($mermaid.length === 0) return

    const runMermaidFn = () => runMermaid($mermaid)
    btf.addGlobalFn('themeChange', runMermaidFn, 'mermaid')
    window.loadMermaid ? runMermaidFn() : btf.getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaidFn)
  }

  btf.addGlobalFn('encrypt', loadMermaid, 'mermaid')
  window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
})()</script></div><script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script defer data-pjax src="/js/pig.js"></script><script src="/js/weather.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="text-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="站内搜索..." type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>